package com.controller;

import com.bean.LoginInfo;
import com.bean.User;
import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping("/login")
    public String login(User user, Map<String, Object> moudle, HttpServletRequest req) {
        boolean res = userService.checkUser(user.getName(), user.getPassword());
        if (res) {
            moudle.put("user", user.getName());
            req.getSession().setAttribute("login", "login");

            List<LoginInfo> loginInfo = userService.getLoginInfo(user.getName());
            moudle.put("list", loginInfo);
            return "main";
        }
        moudle.put("message", "用户或者密码错误");
        return "login";
    }
}
